#!/usr/bin/python
#coding:utf-8
from skimage import io, transform
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
from pylab import mpl

mpl.rcParams['font.sans-serif']=['SimHei'] #正常显示中文标签
mpl.rcParams['axes.unicode_minus']=False # 正常显示正负号

# 对图片与处理，并显示效果
def load_image(path):
    # 新建图并命名
    fig = plt.figure("Centre and Resize")
    img = io.imread(path)
    img = img / 255.0 #像素规划到0~1之间

    ax0 = fig.add_subplot(131) # 建立一行三列的子图
    ax0.set_xlabel(u'Original Picture')
    ax0.imshow(img)

    #找到图片的最短边
    short_edge = min(img.shape[:2])
    y = (img.shape[0] - short_edge) / 2
    x = (img.shape[1] - short_edge) / 2
    # 取出切分后的中心图
    crop_img = img[y:y+short_edge, x:x+short_edge]

    ax1 = fig.add_subplot(132) #放到一行三列的第二个位置
    ax1.set_xlabel(u'Centre Picture')
    ax1.imshow(crop_img)
    
    re_img = transform.resize(crop_img, (224, 224))

    ax2 = fig.add_subplot(133) #放到一行三列的第3个位置
    ax2.set_xlabel(u'Resize Picture')
    ax2.imshow(re_img)

    img_ready = re_img.reshape((1, 224, 224, 3))

    return img_ready

# 把一个数字表示成百分比的格式 
def percent(value):
    return '%.2f%%' % (value * 100)

